<!DOCTYPE html>
<script src="../../../resources/js-test.js"></script>
<script>
jsTestIsAsync = true;
description("document.activeElement should return a valid and " +
    "focusable element after changing focusability in DOMFocusOut.");

document.addEventListener("DOMFocusOut", function() {
    debug("DOMFocusOut is called");
    holder.removeChild(willBeRemoved);
    willBeDisabled.disabled = true;
    setTimeout(test, 0);
}, false);

function test() {
    shouldNotBe("document.activeElement", "willBeDisabled");
    shouldBeEqualToString("document.activeElement.id", "body");
    holder.removeChild(willBeDisabled);
    finishJSTest();
}
</script>
<body id=body>
<div id=holder>
<input id=willBeRemoved>
<script>willBeRemoved.focus()</script>
<input id=willBeDisabled>
<script>willBeDisabled.focus()</script>
</div>
</body>
